var app = getApp();

Page({
    data: {
        group: "拼团开始",
        button_text: "我要参团",
        sec: ""
    },
    onLoad: function(o) {
        var a = this;
        app.getUrl(a), app.setNavigationBarColor(a), wx.setNavigationBarTitle({
            title: o.title
        }), app.getUserInfo(function(t) {
            console.log(t), a.setData({
                userInfo: t
            }), t.id == o.user_id ? a.setData({
                button_text: "邀请好友参团",
                button: "invite",
                button_type: "share"
            }) : a.setData({
                button_text: "我要参团",
                button: "join_group"
            });
        }), console.log(o), a.setData({
            id: o.id,
            options: o,
            goods_id: o.goods_id,
            num_peo: Number(o.group_num)
        }), a.reload();
    },
    reload: function(t) {
        var e = this, n = e.data;
        app.util.request({
            url: "entry/wxapp/GoodsInfo",
            cachetime: "0",
            data: {
                goods_id: e.data.goods_id
            },
            success: function(t) {
                for (var o in console.log(t), e.getCountDown(Number(t.data.goods.end_time)), e.setData({
                    goods: t.data.goods
                }), t.data.group) if (6 <= t.data.group[o].name.length && (t.data.group[o].name = t.data.group[o].name.slice(0, 6) + "..."), 
                t.data.group[o].user_id == n.options.user_id) {
                    console.log("已经有开的团了");
                    var a = Number(t.data.group[o].kt_num) - Number(t.data.group[o].yg_num);
                    e.setData({
                        already_group: !0,
                        already: t.data.group[o],
                        sy_num: a.toFixed(0)
                    }), e.refresh();
                }
            }
        });
    },
    refresh: function(t) {
        var a = this, o = a.data.already.id;
        app.util.request({
            url: "entry/wxapp/GroupInfo",
            data: {
                group_id: o
            },
            success: function(t) {
                console.log(t), a.setData({
                    goods_info: t.data
                });
            }
        }), app.util.request({
            url: "entry/wxapp/GetGroupUserInfo",
            data: {
                group_id: o
            },
            success: function(t) {
                for (var o in console.log(t), t.data) wx.getStorageSync("userInfo").name == t.data[o].name && wx.getStorageSync("userInfo").id != a.data.options.user_id && a.setData({
                    button_text: "您已经参过团了",
                    button: "gfawgaw"
                });
                a.setData({
                    group_user: t.data
                });
            }
        });
    },
    getCountDown: function(r) {
        var s = this;
        "拼团开始" == s.data.group && setInterval(function() {
            var t = new Date(), o = new Date(1e3 * r).getTime() - t.getTime(), a = Math.floor(o / 1e3 / 60 / 60) + "", e = Math.floor(o / 1e3 / 60 % 60) + "", n = Math.floor(o / 1e3 % 60) + "";
            0 < o ? (a < 10 && (a = "0" + a), e < 10 && (e = "0" + e), n < 10 && (n = "0" + n), 
            a = a.split(""), e = e.split(""), n = n.split(""), s.setData({
                hour: a,
                min: e,
                sec: n
            })) : s.setData({
                group: "拼团已结束"
            });
        }, 1e3);
    },
    invite: function(t) {
        this.data;
    },
    join_group: function(t) {
        var o = this.data;
        wx.navigateTo({
            url: "place_order?id=" + o.goods.id + "&type=2&group_id=" + o.already.id + "&price=" + o.goods.pt_price
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {
        var t = this.data;
        return {
            title: wx.getStorageSync("users").name + "邀请您一起来拼团",
            path: "/zh_tcwq/pages/collage/group?user_id=" + t.options.user_id + "&goods_id=" + t.options.goods_id,
            success: function(t) {
                console.log(t);
            },
            complete: function(t) {
                console.log("执行");
            }
        };
    }
});